package com.dream.controller;

import dev.langchain4j.community.model.dashscope.QwenChatModel;
import dev.langchain4j.community.model.dashscope.WanxImageModel;
import dev.langchain4j.data.image.Image;
import dev.langchain4j.model.chat.ChatModel;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URI;

/**
 * @description: 聊天Controller
 * @author: LiMG
 * @create: 2025-07-01 17:09:01
 **/
@Tag(name = "聊天接口", description = "聊天接口")
@RestController
@RequestMapping("/chat")
public class ChatController {

    @Operation(summary = "OpenAI聊天")
    @GetMapping("/openai")
    public String openai(@RequestParam("prompt") String prompt) {
        OpenAiChatModel model = OpenAiChatModel.builder()
                .baseUrl("http://langchain4j.dev/demo/openai/v1")
                .apiKey("demo")
                .modelName("gpt-4o-mini")
                .build();
        return model.chat(prompt);
    }

    @Operation(summary = "Deepseek聊天")
    @GetMapping("/deepseek")
    public String deepseek(@RequestParam("prompt") String prompt) {
        OpenAiChatModel model = OpenAiChatModel.builder()
                .baseUrl("https://api.deepseek.com/v1")
                .apiKey(System.getenv("DEEPSEEK_KEY"))
                .modelName("deepseek-chat")
                .build();
        return model.chat(prompt);
    }

    @Operation(summary = "通义千问")
    @GetMapping("/qwen")
    public String qwen(@RequestParam("prompt") String prompt) {
        ChatModel qwenModel = QwenChatModel.builder()
                .apiKey(System.getenv("BAI_LIAN_KEY"))
                .modelName("qwen-max")
                .build();
        return qwenModel.chat(prompt);
    }

    @Operation(summary = "通义万象")
    @GetMapping("/wanx")
    public String wanx(@RequestParam("prompt") String prompt) {
        WanxImageModel wanxImageModel = WanxImageModel.builder()
                .apiKey(System.getenv("BAI_LIAN_KEY"))
                .modelName("wanx2.1-t2i-turbo")
                .build();
        Response<Image> response = wanxImageModel.generate(prompt);
        URI url = response.content().url();
        System.out.println(url);
        return url.toString();
    }

}
